<html>
<head>
	<script type="text/javascript" src="../../scripts/gears_init.js"></script> 
	
	<script type="text/javascript" src="../../scripts/mootools-1.2.2-core.js"></script>
	<script type="text/javascript" src="../../scripts/tools.js"></script>
	<script type="text/javascript" src="../../scripts/mootools-1.2.2.2-more.js"></script>	
	

	
</head>
	<script>
 
 
 
 
function createXMLHttpRequest()
{
 if(window.ActiveXObject)
 {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 else if(window.XMLHttpRequest)
 {
  xmlHttp=new XMLHttpRequest();
 }
}
function handleStateChange()
{
 alert(xmlHttp.readyState);

}
function doRequestUsingGET()
{
 //alert("s");
 createXMLHttpRequest();
 var queryString="/testservlet?p0='1asd'";
 //xmlHttp.onreadystatechange=handleStateChange;
 xmlHttp.open("GET",queryString,true);
 xmlHttp.send(null);
 
}


function login(){
	/*
	var req = new Request({

		url:"../../colaboxServ?p0=1",

		onSuccess: function(txt){
			alert("ok");
		},

		// Our request will most likely succeed, but just in case, we'll add an
		// onFailure method which will let the user know what happened.
		onFailure: function(){
			alert("error");
		}

	});   

	req.send();
		*/
		//http://hi.baidu.com/strongit/blog/item/e1b71dc7082f85ded10060e9.html
    var request = google.gears.factory.create('beta.httprequest');
									 request.open('POST', '../../colaboxServ?mod=notepad&t='+new Date().getTime());
												request.onreadystatechange = function() {
												  if (request.readyState == 4) {												   
															   try {
																			    if (request.status==200){		
																			           // google.gears.workerPool.sendMessage([{ret:"true",val:"request.responseText",Gusername:u,Gpassword:p,msgId:MSG.body[0].msgId}], MSG.sender);	
																			          eval("val="+request.responseText);
                                               
                                               for (i=0;i<=val.length-1;i++){
                                                   //alert(val[i].id+" "+val[i].ret);	
                                                   $(text2).value=val[i].ret;
                                               } 
                                               
																			        // alert("ok");
																			    }else{ 
																			    	    ret=0; 
																			    	 	  alert('err='+request.status);
																			    }
																			    	 
															     } catch(e) {ret=0; }												    
												  }
												};
												
										//var str=json_parse('opsd,"\"" /n /t iueo a""');
									//	var str='\'\{\}\[\]&\,';
										str=$('text1').value;
										//alert(str);
										
			              function toJSON(val){
			              	val=val.replace(/\\/g, "\\\\");
			              	val=val.replace(/"/g, "\\\"");
			              	val=val.replace(/\n/g, "\\n");
			              	return "\""+val+"\"";
			              }
										//alert(toJSON(str));
										function NotepadData()
										{
											this.id="0";
											this.content=str;
											this.title="title";
											this.type="type";
											this.changetime="220202";
									  }
/*
\                         \\
"                        \\\"

*/
                    var notepaddata=new NotepadData; 
										//alert(JSON.encode(str));
										//str=JSON.encode(str);
										//json_parse
										
										//request.send(json_parse('[{"id":1,"title":"1","content":"'+str+'","type":"","changetime":"200202"},{"id":1,"title":"1",content:"content","type":"","changetime":"200202"}]'));
										//request.send('[{"id":1,"title":"1","content":"'+str+'","type":"","changetime":"200202"},{"id":1,"title":"1",content:"content","type":"","changetime":"200202"}]');
										request.send('[{id:1,title:1,content:'+toJSON(str)+',type:"",changetime:200202}]');
										
}


	</script>

<body>	
hello google gdata api
<textarea id=text1 value="\">
</textarea>
<textarea id=text2 value="\">
</textarea>
<div onclick="login()">login</div>



</body>
</html>